﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using MediaWiki.Office.Model.Utilities;

namespace MediaWiki.Office.Model
{
  public class TableRow : Content
  {
    private List<TableCell> _cells = new List<TableCell>();
    private TableRowProperties _properties;

    public new Table Parent
    {
      get { return (Table)base.Parent; }
      set { base.Parent = value; }
    }

    public TableRowProperties Properties
    {
      get { return _properties; }
      set { _properties = value; }
    }

    public List<TableCell> Cells
    {
      get { return _cells; }
      set { _cells = value; }
    }

    public TableRow(Table parent, XElement element)
      : base(parent)
    {
      if (element == null)
        throw new ArgumentNullException("element");

      XNamespace ns = element.Name.Namespace;

      _properties = new TableRowProperties(this, element.Element(ns + "trPr"));

      var tableCells = from e in element.Elements(ns + "tc")
                       select new TableCell(this, e);

      _cells.AddRange(tableCells);
    }
  }
}